//
//  PersonVC.m
//  PlayShow
//
//  Created by hff on 2018/4/20.
//  Copyright © 2018年 threeTi. All rights reserved.
//

#import "PersonVC.h"
#import "PersonTopView.h"
#import "SettingCell.h"
#import "AppMacro.h"
#import "PersonalDataVC.h"
#import "SettingVC.h"
#import "HUD.h"

@interface PersonVC ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *settingTableView;
@property (strong, nonatomic) NSMutableArray *dataArray;//数据
@property (strong, nonatomic) NSMutableArray *imagesArray;//数据
@property (strong, nonatomic) PersonTopView *topView;
@end

@implementation PersonVC


-(PersonTopView *)topView
{
    if (!_topView) {
        _topView = [[[NSBundle mainBundle] loadNibNamed:@"PersonTopView" owner:self options:nil] lastObject];
        [_topView setFrame:CGRectMake(0, 0, UIScreenWidth, 168)];
        [_topView setBackgroundColor:[UIColor whiteColor]];
        
        //进入个人资料界面
        [_topView.personalBtn addTarget:self action:@selector(personalBtnClicked) forControlEvents:UIControlEventTouchUpInside];
        
        //开通学籍点击事件
        UITapGestureRecognizer *reg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openBtnClicked)];
        [_topView.openBngView setUserInteractionEnabled:YES];
        [_topView.openBngView addGestureRecognizer:reg];
    }
    return _topView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
   
     self.navigationItem.title = @"我的";
    
    //注册自定义cell
    [self.settingTableView registerNib:[UINib nibWithNibName:@"SettingCell"  bundle:nil] forCellReuseIdentifier:@"SettingCell" ];
    [self.settingTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
   // [self.settingTableView setBackgroundColor:[UIColor clearColor]];
    
    UIView *topBngView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 168)];
    [topBngView addSubview:self.topView];
    [self.settingTableView setTableHeaderView:topBngView];
    
    self.dataArray = [NSMutableArray arrayWithObjects:@"设置", @"离线缓存",  nil];
    self.imagesArray = [NSMutableArray arrayWithObjects:@"setting.png",@"offline.png", nil];
}

-(void)personalBtnClicked
{
    PersonalDataVC *detialView = [[UIStoryboard storyboardWithName:@"Person" bundle:nil] instantiateViewControllerWithIdentifier:@"PersonalDataVC"];
    [self.navigationController pushViewController:detialView animated:YES];
}

-(void)openBtnClicked
{
    [HUD showAlertWithTitle:DEFAULT_ALERT_MESSAGE];
}

#pragma mark *** tableView_delegate  ***
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SettingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SettingCell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell.contentView setBackgroundColor:[UIColor whiteColor]];
    
    [cell.settingImage setImage:[UIImage imageNamed:[self.imagesArray objectAtIndex:indexPath.row]]];
    [cell.settingTitle setText:[self.dataArray objectAtIndex:indexPath.row]];
    
    return cell;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  [self.dataArray count];
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 48;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        SettingVC *settingView = [[UIStoryboard storyboardWithName:@"Person" bundle:nil] instantiateViewControllerWithIdentifier:@"SettingVC"];
        [self.navigationController pushViewController:settingView animated:YES];
    }
  
    
    if (indexPath.row == 1)
    {
        [HUD showAlertWithTitle:DEFAULT_ALERT_MESSAGE];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
